package com.sk.bilibili.apiMapper.component;

import com.sk.bilibili.apiMapper.interfaces.StringConverter;
import lombok.SneakyThrows;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 邵康
 * @date 2021/7/11 16:40
 */
public class StringConverterCache {

    private Map<Class<?extends StringConverter>,StringConverter> cache;

    public StringConverterCache() {
        cache=new HashMap<>();
    }

    @SneakyThrows
    public StringConverter getStringConverter(Class<? extends StringConverter> value) {
        if(!cache.containsKey(value)){
            cache.put(value,value.newInstance());
        }
        return cache.get(value);
    }

}
